const server = require('./../server/dynamicServer');
let dynamic = new server();
function dynamicServer() {
    let result = {};
    this.queryAll = (req,res) => {
        dynamic.selectAll(req,rows => {
            if (rows){
                result.code=1;
                result.data = rows;
            } else{
                result.code=0;
                result.data = null;
            }
            res.write(JSON.stringify(result));
            res.end();
        })
    }
    this.addDynamic = (req,res) => {
        dynamic.add(req.body,rows => {
            if (rows){
                result.code=1;
                result.msg = '添加成功';
            } else{
                result.code=0;
                result.msg = '添加失败';
            }
            res.write(JSON.stringify(result));
            res.end();
        })
    }
    this.delete = (req,res) => {
        dynamic.del(req.body, rows => {
            if (rows){
                result.code=1;
                result.msg = '删除成功';
            } else{
                result.code=0;
                result.msg = '删除失败';
            }
            res.write(JSON.stringify(result));
            res.end();
        })
    }
    this.delAll = (req,res) => {
        //批量删除
        dynamic.delAll(req.body,rows => {
            if (rows){
                result.code=1;
                result.msg = '删除成功';
            } else{
                result.code=0;
                result.msg = '删除失败';
            }
            res.write(JSON.stringify(result));
            res.end();
        })
    }
    this.search = (req,res) => {
        dynamic.search(req.body, rows => {
            if (rows){
                result.code=1;
                result.msg = '查询成功';
            } else{
                result.code=0;
                result.msg = '查询失败';
            }
            res.write(JSON.stringify(result));
            res.end();
        })
    }
}
module.exports = dynamicServer;
